package com.objectcarpentry.kaylee.gstreamer;

import org.eclipse.core.runtime.Plugin;
import org.gstreamer.Gst;
import org.osgi.framework.BundleContext;

import com.objectcarpentry.kaylee.IPlayer;

/**
 * The activator class controls the plug-in life cycle
 */
public class KayleeGStreamerPlugin extends Plugin {

	// The plug-in ID
	public static final String PLUGIN_ID = "com.objectcarpentry.cappuccino.player";

	// The shared instance
	private static KayleeGStreamerPlugin plugin;
	
	// The player
	protected KayleeGStreamerPlayer player;

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
		Gst.init();
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		if (player != null){
			player.dispose();
		}
		Gst.deinit();
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static KayleeGStreamerPlugin getDefault() {
		return plugin;
	}
	
	public IPlayer getPlayer(){
		if (player == null){
			player = new KayleeGStreamerPlayer();
		}
		return player;
	}
	
	
	
}
